package com.warmlight.voicepacket.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.umeng.analytics.MobclickAgent;
import com.warmlight.voicepacket.Add2ListActivity;
import com.warmlight.voicepacket.PlayDeatalActivity;
import com.warmlight.voicepacket.R;
import com.warmlight.voicepacket.base.MBaseAdapter;
import com.warmlight.voicepacket.data.PlaydeatalData;
import com.warmlight.voicepacket.data.RecommendFeed;
import com.warmlight.voicepacket.data.TempData;
import com.warmlight.voicepacket.data.eventbus.PlayerServiceData;
import com.warmlight.voicepacket.data.eventbus.ShareUnlock;
import com.warmlight.voicepacket.dbmanager.DBFloatPlayListDetailDaoHelp;
import com.warmlight.voicepacket.fragment.CopyShareFragment;
import com.warmlight.voicepacket.fragment.CustomBottomSheetDialogFragment;
import com.warmlight.voicepacket.http.Callback;
import com.warmlight.voicepacket.http.HttpClient;
import com.warmlight.voicepacket.http.HttpConfig;
import com.warmlight.voicepacket.ui.Add2NetListActivity;
import com.warmlight.voicepacket.utils.ClickLog;
import com.warmlight.voicepacket.utils.GlideRoundTransform;
import com.warmlight.voicepacket.utils.JSONUtils;
import com.warmlight.voicepacket.utils.MobClickHelper;
import com.warmlight.voicepacket.utils.SPUtils;
import com.zhuge.analysis.stat.ZhugeSDK;

import org.greenrobot.eventbus.EventBus;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import okhttp3.Call;

import static com.warmlight.voicepacket.db.VoicePacketDBHelper.AUDIO_ID;
import static com.warmlight.voicepacket.db.VoicePacketDBHelper.LIST_ID;

/**
 * 发现页面的音频列表adapter
 * Created by jason on 2018/5/31.
 */

public class FeedListAdapter extends MBaseAdapter {

    private ImageView mLastView,mLastAnime;
    private RecommendFeed.DataBean.ListBean mLastData;
    private final RequestOptions options;
    private String category_id;

    interface PositionCallBack{
        void callBack(int position);
    }

    private PositionCallBack pos;

    public void setPostionCallBack(PositionCallBack pos){
        this.pos = pos;
    }

    public FeedListAdapter(Context context, List<RecommendFeed.DataBean.ListBean> list,String category_id) {
        super(context, list);
        options = new RequestOptions();
        options.transform(new GlideRoundTransform(mContext)).placeholder(R.drawable.icon_roud_placeholder).error(R.drawable.icon_roud_error).dontAnimate();
        this.category_id = category_id;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = View.inflate(mContext, R.layout.item_recommend_feed, null);
            holder = new ViewHolder();
            holder.iv_feed = (ImageView) convertView.findViewById(R.id.iv_feed);
            holder.iv_play_state = (ImageView) convertView.findViewById(R.id.iv_play_state);
            holder.iv_feed_anime = (ImageView) convertView.findViewById(R.id.iv_feed_anime);
            holder.tv_feed_class = (TextView) convertView.findViewById(R.id.tv_feed_class);
            holder.tv_feed_content = (TextView) convertView.findViewById(R.id.tv_feed_content);
            holder.tv_feed_time = (TextView) convertView.findViewById(R.id.tv_feed_time);
            holder.tv_audio_name = (TextView) convertView.findViewById(R.id.tv_audio_name);
            holder.tv_feed_zan = (TextView) convertView.findViewById(R.id.tv_feed_zan);
            holder.tv_feed_share = (TextView) convertView.findViewById(R.id.tv_feed_share);
            holder.tv_feed_fav = (TextView) convertView.findViewById(R.id.tv_feed_fav);
            holder.iv_item_share_use = (ImageView) convertView.findViewById(R.id.iv_item_share_use);
            convertView.setTag(holder);
        }

        final RecommendFeed.DataBean.ListBean data = (RecommendFeed.DataBean.ListBean)mList.get(position);
        holder.tv_feed_class.setVisibility(View.GONE);
//        holder.tv_feed_class.setText(data.getCategory_name());
//        if(position % 3 == 0){
//            holder.tv_feed_class.setBackgroundResource(R.drawable.bg_feed_class);
//        }else if(position % 3 == 1){
//            holder.tv_feed_class.setBackgroundResource(R.drawable.bg_feed_class2);
//        }else{
//            holder.tv_feed_class.setBackgroundResource(R.drawable.bg_feed_class3);
//        }
//        RequestOptions options = new RequestOptions().skipMemoryCache(false);
//        options.transform(new GlideRoundTransform(mContext)).placeholder(R.drawable.icon_roud_placeholder).error(R.drawable.icon_roud_error).dontAnimate();
        if (options != null) {
            Glide.with(mContext).load(data.getCover_pic()).apply(options).into(holder.iv_feed);
        }
        holder.tv_feed_content.setText(data.getTitle());
        holder.tv_feed_time.setText(data.getDuration()+"\"");
        holder.tv_audio_name.setText(data.getCover_name());
        if(position % 3 == 0){
            holder.tv_audio_name.setBackgroundResource(R.drawable.bg_audio_name);
        }else if(position % 3 == 1){
            holder.tv_audio_name.setBackgroundResource(R.drawable.bg_audio_name2);
        }else{
            holder.tv_audio_name.setBackgroundResource(R.drawable.bg_audio_name3);
        }
        //锁
        final String isShare = data.getIs_share();//1 fenxiang 0 bufenxiang
        final String isUnlock = data.getIs_unlocked();//1jiesuo 0weijiesuo
        if ("1".equals(isShare) && "0".equals(isUnlock)){//未解锁
            holder.iv_item_share_use.setVisibility(View.VISIBLE);
        }else{
            holder.iv_item_share_use.setVisibility(View.GONE);
        }

        RecommendFeed.DataBean.ListBean.ShareInfoBean share_info = data.getShare_info();
        final PlaydeatalData.DataBean.ShareBean shareBean = new PlaydeatalData.DataBean.ShareBean();
        if (share_info != null) {
            shareBean.setTitle(share_info.getTitle());
            shareBean.setPic_url(share_info.getPic_url());
            shareBean.setH5_url(share_info.getH5_url());
            shareBean.setDesc(share_info.getDesc());
        }

        holder.tv_audio_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if ("1".equals(isShare) && "0".equals(isUnlock)){//未解锁
                    //如果有锁就去跳转分享
                    new CustomBottomSheetDialogFragment(shareBean, new CustomBottomSheetDialogFragment.ShareCallBack() {
                        @Override
                        public void shareSuccess(boolean isSuccess) {
                            shareResult(isSuccess,data.getId(), data.getCover_id(),position);
                        }
                    },true).show(((FragmentActivity)mContext).getSupportFragmentManager(), "feedlist");
                    //推荐页feed被锁条目的整体点击
                    MobclickAgent.onEvent(mContext.getApplicationContext(), MobClickHelper.DIS_VOICE_LOCK,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                    HashMap<String,Object> temp = new HashMap<>();
                    temp.put("推荐页feed被锁条目的整体点击",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                    ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_LOCK,temp);

                    //
                    ClickLog.clickLog(ClickLog.dis_voice_lock,data.getCover_id(),data.getCover_id(),category_id);
                }else{
                    Intent intentDetail = new Intent(mContext, PlayDeatalActivity.class);
                    intentDetail.putExtra(LIST_ID,data.getCover_id());
                    mContext.startActivity(intentDetail);

                    if("1".equals(isShare) && "1".equals(isUnlock)){
                        //推荐页feed分享后播单标签
                        MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OTAG,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                        HashMap<String,Object> temp = new HashMap<>();
                        temp.put("推荐页feed被锁条目的整体点击",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                        ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OTAG,temp);

                        //
                        ClickLog.clickLog(ClickLog.dis_voice_otag,data.getCover_id(),data.getCover_id(),category_id);
                    }else{
                        //推荐页feed非分享播单标签
                        MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_TAG,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                        HashMap<String,Object> temp = new HashMap<>();
                        temp.put("推荐页feed非分享播单标签",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                        ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_TAG,temp);
                        //
                        ClickLog.clickLog(ClickLog.dis_voice_tag,data.getCover_id(),data.getCover_id(),category_id);
                    }
                }


            }
        });

        holder.tv_feed_zan.setText(data.getStar());
        holder.tv_feed_share.setText(data.getShare());
        holder.tv_feed_fav.setText(data.getCollect());
        if (SPUtils.isLogined()){
            boolean is_collect = data.isIs_collect();
            if (is_collect){
                Drawable drawable = mContext.getResources().getDrawable(R.drawable.icon_fav_y);
//一定要加这行！！！！！！！！！！！
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                holder.tv_feed_fav.setCompoundDrawables(drawable,null,null,null);
            }else{
                Drawable drawable = mContext.getResources().getDrawable(R.drawable.icon_fav);
//一定要加这行！！！！！！！！！！！
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                holder.tv_feed_fav.setCompoundDrawables(drawable,null,null,null);
            }
        }else{
            boolean exists = DBFloatPlayListDetailDaoHelp.isExists(mContext, data.getId());
            if (exists){
                Drawable drawable = mContext.getResources().getDrawable(R.drawable.icon_fav_y);
//一定要加这行！！！！！！！！！！！
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                holder.tv_feed_fav.setCompoundDrawables(drawable,null,null,null);
            }else{
                Drawable drawable = mContext.getResources().getDrawable(R.drawable.icon_fav);
//一定要加这行！！！！！！！！！！！
                drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                holder.tv_feed_fav.setCompoundDrawables(drawable,null,null,null);
            }
        }


        holder.tv_feed_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                new CustomBottomSheetDialogFragment(null).show(((FragmentActivity)mContext).getSupportFragmentManager(), "Dialog");

                if ("1".equals(isShare) && "0".equals(isUnlock)){//未解锁
                    //如果有锁就去跳转分享
                    new CustomBottomSheetDialogFragment(shareBean, new CustomBottomSheetDialogFragment.ShareCallBack() {
                        @Override
                        public void shareSuccess(boolean isSuccess) {
                            shareResult(isSuccess,data.getId(),data.getCover_id(),position);
                        }
                    },true).show(((FragmentActivity)mContext).getSupportFragmentManager(), "feedlist");
                    //推荐页feed被锁条目的整体点击
                    MobclickAgent.onEvent(mContext.getApplicationContext(), MobClickHelper.DIS_VOICE_LOCK,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                    HashMap<String,Object> temp = new HashMap<>();
                    temp.put("推荐页feed被锁条目的整体点击",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                    ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_LOCK,temp);
                    //
                    ClickLog.clickLog(ClickLog.dis_voice_lock,data.getCover_id(),data.getCover_id(),category_id);
                }else{
                    TempData.AudioData = (RecommendFeed.DataBean.ListBean) mList.get(position);
                    CopyShareFragment copyShareFragment = new CopyShareFragment();
                    copyShareFragment.setOnShareClick(new CopyShareFragment.ShareClick() {
                        @Override
                        public void click() {
                            String share = data.getShare();
                            share = (Integer.valueOf(share) + 1)+"";
                            data.setShare(share);
                            holder.tv_feed_share.setText(share);
                        }
                    });
                    copyShareFragment.show(((FragmentActivity)mContext).getSupportFragmentManager(), "Dialog");
                    if("1".equals(isShare) && "1".equals(isUnlock)){
                        //推荐页feed分享后条目的分享按钮
                        MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OSHARE,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                        HashMap<String,Object> temp = new HashMap<>();
                        temp.put("推荐页feed分享后条目的分享按钮",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                        ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OSHARE,temp);
                        //
                        ClickLog.clickLog(ClickLog.dis_voice_oshare,data.getCover_id(),data.getCover_id(),category_id);
                    }else{
                        //推荐页feed非分享条目的分享按钮
                        MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_SHARE,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                        HashMap<String,Object> temp = new HashMap<>();
                        temp.put("推荐页feed非分享条目的分享按钮",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                        ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_SHARE,temp);
                        //
                        ClickLog.clickLog(ClickLog.dis_voice_share,data.getCover_id(),data.getCover_id(),category_id);
                    }
                }


            }
        });

        if ("1".equals(isShare) && "0".equals(isUnlock)){
            holder.iv_play_state.setImageResource(R.drawable.icon_audio_lock);

            // 暂停动画
            Drawable d = holder.iv_feed_anime.getDrawable();
            if (d instanceof AnimationDrawable) {
                ((AnimationDrawable) holder.iv_feed_anime.getDrawable()).stop();
            }
//            holder.iv_feed_anime.setImageResource(R.drawable.icon_audio_play);
            holder.iv_feed_anime.setImageResource(R.drawable.frame3);
        }else {

            if (data.isPlaying()) {
                holder.iv_play_state.setImageResource(R.drawable.icon_audio_pause);
                // 放动画
                holder.iv_feed_anime.setImageResource(R.drawable.anime_playing);
                ((AnimationDrawable) holder.iv_feed_anime.getDrawable()).start();
            } else {
                holder.iv_play_state.setImageResource(R.drawable.icon_audio_play);
                // 暂停动画
                Drawable d = holder.iv_feed_anime.getDrawable();
                if (d instanceof AnimationDrawable) {
                    ((AnimationDrawable) holder.iv_feed_anime.getDrawable()).stop();
                }
//            holder.iv_feed_anime.setImageResource(R.drawable.icon_audio_play);
                holder.iv_feed_anime.setImageResource(R.drawable.frame3);
            }
        }

        //变更需求，改为点击整个item播放
//        holder.iv_feed.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if(data.isPlaying()){
//                    holder.iv_play_state.setImageResource(R.drawable.icon_audio_play);
//                    data.setPlaying(false);
//
//                    Drawable d = holder.iv_feed_anime.getDrawable();
//                    if(d instanceof AnimationDrawable){
//                        ((AnimationDrawable)holder.iv_feed_anime.getDrawable()).stop();
//                        holder.iv_feed_anime.setImageResource(R.drawable.frame3);
//                    }
//
//                    EventBus.getDefault().post(new PlayerServiceData(PlayerServiceData.PAUSE,data.getUrl()));
//                }else{
//                    if(mLastData != null && mLastView != null && mLastAnime != null){
//                        mLastView.setImageResource(R.drawable.icon_audio_play);
//                        mLastData.setPlaying(false);
//                        Drawable d = mLastAnime.getDrawable();
//                        if(d instanceof AnimationDrawable){
//                            ((AnimationDrawable)mLastAnime.getDrawable()).stop();
//                            mLastAnime.setImageResource(R.drawable.frame3);
//                        }
//                    }
//                    holder.iv_play_state.setImageResource(R.drawable.icon_audio_pause);
//                    data.setPlaying(true);
//                    EventBus.getDefault().post(new PlayerServiceData(PlayerServiceData.PLAY,data.getUrl()));
//
//                    holder.iv_feed_anime.setImageResource(R.drawable.anime_playing);
//                    ((AnimationDrawable)holder.iv_feed_anime.getDrawable()).start();
//
//                    mLastView = holder.iv_play_state;
//                    mLastData = data;
//                    mLastAnime = holder.iv_feed_anime;
//
//                    //FIXME 没时间了，先这么做。什么手段都先用着
//                    TempData.mLastAnime = holder.iv_feed_anime;
//                    TempData.mLastData = data;
//                    TempData.mLastView = holder.iv_play_state;
//                }
//            }
//        });

        holder.tv_feed_fav.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if ("1".equals(isShare) && "0".equals(isUnlock)){//未解锁
                    //如果有锁就去跳转分享
                    new CustomBottomSheetDialogFragment(shareBean, new CustomBottomSheetDialogFragment.ShareCallBack() {
                        @Override
                        public void shareSuccess(boolean isSuccess) {
                            shareResult(isSuccess,data.getId(),data.getCover_id(),position);
                        }
                    },true).show(((FragmentActivity)mContext).getSupportFragmentManager(), "feedlist");
                    //推荐页feed被锁条目的整体点击
                    MobclickAgent.onEvent(mContext.getApplicationContext(), MobClickHelper.DIS_VOICE_LOCK,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                    HashMap<String,Object> temp = new HashMap<>();
                    temp.put("推荐页feed被锁条目的整体点击",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                    ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_LOCK,temp);
                    //
                    ClickLog.clickLog(ClickLog.dis_voice_lock,data.getCover_id(),data.getCover_id(),category_id);
                }else{
                    if (SPUtils.isLogined()){
                        Intent intent = new Intent(mContext, Add2NetListActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("audio_id", (RecommendFeed.DataBean.ListBean) mList.get(position));
                        intent.putExtras(bundle);
                        mContext.startActivity(intent);
                    }else {
                        Intent intent = new Intent(mContext, Add2ListActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable(AUDIO_ID, (RecommendFeed.DataBean.ListBean) mList.get(position));
                        intent.putExtras(bundle);
                        mContext.startActivity(intent);
                    }


                    if("1".equals(isShare) && "1".equals(isUnlock)){
                        //推荐页feed分享后条目的收藏按钮
                        MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OCLOT,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                        HashMap<String,Object> temp = new HashMap<>();
                        temp.put("推荐页feed分享后条目的收藏按钮",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                        ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OCLOT,temp);

                        //
                        ClickLog.clickLog(ClickLog.dis_voice_oclot,data.getCover_id(),data.getCover_id(),category_id);
                    }else{
                        //推荐页feed非分享条目的收藏按钮
                        MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_CLOT,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                        HashMap<String,Object> temp = new HashMap<>();
                        temp.put("推荐页feed非分享条目的收藏按钮",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                        ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_CLOT,temp);
                        //
                        ClickLog.clickLog(ClickLog.dis_voice_clot,data.getCover_id(),data.getCover_id(),category_id);
                    }



                }


            }
        });

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if ("1".equals(isShare) && "0".equals(isUnlock)){//未解锁
                    //如果有锁就去跳转分享
                    new CustomBottomSheetDialogFragment(shareBean, new CustomBottomSheetDialogFragment.ShareCallBack() {
                        @Override
                        public void shareSuccess(boolean isSuccess) {
                            shareResult(isSuccess,data.getId(),data.getCover_id(),position);
                        }
                    },true).show(((FragmentActivity)mContext).getSupportFragmentManager(), "feedlist");
                    //推荐页feed被锁条目的整体点击
                    MobclickAgent.onEvent(mContext.getApplicationContext(), MobClickHelper.DIS_VOICE_LOCK,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                    HashMap<String,Object> temp = new HashMap<>();
                    temp.put("推荐页feed被锁条目的整体点击",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                    ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_LOCK,temp);
                    //
                    ClickLog.clickLog(ClickLog.dis_voice_lock,data.getCover_id(),data.getCover_id(),category_id);
                }else{
                    if(data.isPlaying()){
                        holder.iv_play_state.setImageResource(R.drawable.icon_audio_play);
                        data.setPlaying(false);

                        Drawable d = holder.iv_feed_anime.getDrawable();
                        if(d instanceof AnimationDrawable){
                            ((AnimationDrawable)holder.iv_feed_anime.getDrawable()).stop();
                            holder.iv_feed_anime.setImageResource(R.drawable.frame3);
                        }

                        EventBus.getDefault().post(new PlayerServiceData(PlayerServiceData.PAUSE,data.getUrl()));
                    }else{
                        if(mLastData != null && mLastView != null && mLastAnime != null){
                            mLastView.setImageResource(R.drawable.icon_audio_play);
                            mLastData.setPlaying(false);
                            Drawable d = mLastAnime.getDrawable();
                            if(d instanceof AnimationDrawable){
                                ((AnimationDrawable)mLastAnime.getDrawable()).stop();
                                mLastAnime.setImageResource(R.drawable.frame3);
                            }
                        }
                        holder.iv_play_state.setImageResource(R.drawable.icon_audio_pause);
                        data.setPlaying(true);
                        EventBus.getDefault().post(new PlayerServiceData(PlayerServiceData.PLAY,data.getUrl()));

                        holder.iv_feed_anime.setImageResource(R.drawable.anime_playing);
                        ((AnimationDrawable)holder.iv_feed_anime.getDrawable()).start();

                        mLastView = holder.iv_play_state;
                        mLastData = data;
                        mLastAnime = holder.iv_feed_anime;

                        //FIXME 没时间了，先这么做。什么手段都先用着
                        TempData.mLastAnime = holder.iv_feed_anime;
                        TempData.mLastData = data;
                        TempData.mLastView = holder.iv_play_state;

                        if("1".equals(isShare) && "1".equals(isUnlock)){
                            //推荐页feed分享后播放
                            MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OPLAY,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                            HashMap<String,Object> temp = new HashMap<>();
                            temp.put("推荐页feed分享后播放",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                            ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_OPLAY,temp);

                            //
                            ClickLog.clickLog(ClickLog.dis_voice_oplay,data.getId(),data.getCover_id(),category_id);
                        }else{
                            //推荐页feed非分享播放
                            MobclickAgent.onEvent(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_PLAY,((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle());
                            HashMap<String,Object> temp = new HashMap<>();
                            temp.put("推荐页feed非分享播放",((RecommendFeed.DataBean.ListBean) mList.get(position)).getTitle().toString());
                            ZhugeSDK.getInstance().track(mContext.getApplicationContext(),MobClickHelper.DIS_VOICE_PLAY,temp);
                            //
                            ClickLog.clickLog(ClickLog.dis_voice_play,data.getId(),data.getCover_id(),category_id);
                        }

                        showSBTips(position);
                    }

                }
            }
        });

        return convertView;
    }

    private void showSBTips(int position) {
        if (pos != null){
            pos.callBack(position);
        }
    }

    private void shareResult(boolean isSuccess, final String id, final String cover_id, final int position){
        if (isSuccess) {
            TreeMap<String,String> map = new TreeMap<>();
            map.put("audio_id",id);
            map.put("type","1");
            HttpClient.post(HttpConfig.SERVER + HttpConfig.SHARE, map, new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {

                }

                @Override
                public void onResponse(Call call, String response){
//                    String string = response.body().string();
                    ArrayList<Map<String, String>> listMapByJson = JSONUtils.getListMapByJson(response);
                    if (listMapByJson.size()>0){
                        Map<String, String> map1 = listMapByJson.get(0);
                        if ("200".equals(map1.get("code"))){
                            EventBus.getDefault().post(new ShareUnlock(true,position,cover_id));
//                            ((RecommendFeed.DataBean.ListBean) mList.get(position)).setUnlockSuccess(true);
                        }
                    }
                }
            });
        }
    }

    private class ViewHolder {
        ImageView iv_feed;
        ImageView iv_play_state;
        ImageView iv_feed_anime;
        TextView tv_feed_class;
        TextView tv_feed_content;
        TextView tv_feed_time;
        TextView tv_audio_name;
        TextView tv_feed_zan;
        TextView tv_feed_share;
        TextView tv_feed_fav;
        ImageView iv_item_share_use;
    }

    public void addBefore(List<RecommendFeed.DataBean> list){
        if(mList == null){
            mList = new ArrayList<>();
        }
        mList.addAll(0,list);
        notifyDataSetChanged();
    }

    public List<RecommendFeed.DataBean.ListBean> getList(){
        return mList;
    }

}
